<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>产品名称</span>
              <el-input class="tel-value" v-model="params_list.name" placeholder="请输入产品名称"></el-input>
            </div>
            <div class="item-inline">
              <span>商品类型</span>
              <el-select class="tel-value" v-model="params_list.type" placeholder="请选择">
                <el-option v-for="(item,index) in types" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          服务单价格列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" :loading="boo.isExport" @click="exportRow">{{boo.isExport ? '请稍后……' : '导出'}}</el-button>
          </div>
        </div>
        <el-table :data="servicelist" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="img" label="产品图片" width="130" align="center">
            <template slot-scope="scope">
              <img class="logo" :src="scope.row.img"/>
            </template>
          </el-table-column>
          <el-table-column prop="sum" label="产品编码" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="name" label="产品名称" width="150" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.name}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="适用地区" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="price" label="价格" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="type" label="商品类型" align="center" >
          </el-table-column>
          <el-table-column prop="status" label="状态" align="center">
          </el-table-column>
        </el-table>
        <div v-if="servicelist.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- 添加产品 -->
    <el-dialog  :visible.sync="boo.showDialog" class="jx-dialog" width="80%">
      <div slot="title" class="header-title">
        <span class="title-name">添加产品</span>
      </div>
      <el-form ref="form" :model="currentRow" :rules="rules" label-width="90px" class="jx-form">
        <div class="jx-detail">
          <div class="detail-item">
            <div class="item_2">
              <div class="title">基本信息</div>
              <el-form-item label="产品类型：" prop="warehouse_num">
                <el-select class="tel-value" v-model="currentRow.type" placeholder="请选择">
                  <el-option label="服务" value="1"></el-option>
                  <el-option label="其他" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="产品分类：" prop="warehouse_num">
                <el-cascader
                  class="tel-value"
                  v-model="currentRow.item2"
                  :options="options"
                  :props="props"
                  @change="handleChange">
                </el-cascader>
              </el-form-item>
              <el-form-item label="产品名称：" prop="warehouse_num">
                <el-input class="tel-value" v-model="currentRow.item3" placeholder="请输入产品名称"></el-input>
              </el-form-item>
              <el-form-item label="适用车系：" prop="warehouse_num">
                <el-select class="tel-value" v-model="currentRow.item4" placeholder="请选择">
                  <el-option label="全系" value="1"></el-option>
                  <el-option label="其他" value="2"></el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="item_2">
              <div class="title">产品清单</div>
              <div class="list">
                <div class="right">
                  <el-input class="tel-value" type="textarea" row="3" v-model="currentRow.item6" placeholder="请输入产品清单"></el-input>
                </div>
              </div>
              <div class="title" style="margin-top: 35px;">服务说明</div>
              <div class="list" v-for="(item,index) in currentRow.item7" :key="index">
                <div class="right">
                  <el-input class="tel-value" v-model="item.text" placeholder="请输入服务说明"></el-input>
                  <el-button type="text" size="small" @click="addInfo">增加</el-button>
                  <el-button v-if="currentRow.item7.length != 1" type="text" size="small" @click="deleteInfo(index)">删除</el-button>
                </div>
              </div>
            </div>
          </div>
        </div> 
      </el-form>
      <div class="btn-container">
        <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow('form')">生成产品</el-button>
      </div>
    </el-dialog>
	</div>
</template>

<script>
  import list from 'static/json/finance/service.json'
  const typelist = [
    {value: '1',label: '汽车保养', children: [{value: '1-1',label: '洗车'}]},
    {value: '2',label: '汽车维修', children: [{value: '2-1',label: '轮胎'}]},
  ]
	export default {
		data() {
			return {
        https: {
          // list: this.$api.product.supplylist,
          // common: this.$api.common.dict
        },
        boo: {
          loading: false,
          showDialog: false,
          saveing: false,
        },
        other: {
          allRow: 1,
        },
        servicelist: list,
        params_list: {
          page: 1,
          size: 10,
          type: '',
          name: '',
        },
        types: '',
        currentRow: {item7: [{text: ''}],},
        options: [
          {value: '1',label: '汽车服务', children: [
            {value: '1-1',label: '洗车'},
            {value: '1-2',label: '保养'}
          ]},
          {value: '2',label: '其他',},
        ],
        props: {
          expandTrigger: 'click', 
          value: 'value',
          label: 'label',
        },
        rules: {
          district_code: [{ required: true, message: '请输入地区编号', trigger: 'blur' }],
          district_name: [{ required: true, message: '请输入地区名称', trigger: 'blur' }],
        },
        typelist: typelist,
        props: {
          expandTrigger: 'click', 
          value: 'value',
          label: 'label',
        },
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      // _self.getDict('shopProductCatalog')
    },
		methods: {
      getDict(type){
        let _self = this
        let params = {
          dictCode: type,
        }
        // 新建判断Map
        // let actions = (i,list,)=>{
        //   return new Map([
        //     ['shopProductCatalog',()=>{
        //       _self.types = list
        //     }]
        //   ]).get(i).call(this)
        // }
        // let success = (res)=>{
        //   if(res.data.retCode == 1){
        //     actions(type,res.data.retObject)
        //   }else{
        //     _self.$message.error(res.data.retMsg)
        //   }
        // }
        // _self.$axios.get(_self.https.common, params, success) 
      },
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          serviceProductName: _self.params_list.name,
          shopProductCatalog: _self.params_list.type,
          orderBy: '',
        }
        // _self.boo.loading = true
        // let success = (res)=>{
        //   res = res.data
        //   if(res.retCode == 1){
        //     _self.servicelist = res.retObject.list
        //     _self.other.allRow = Number(res.retObject.totalRow)
        //   }else{
        //     _self.$message.error(res.retMsg)
        //   }
        //   _self.boo.loading = false
        // }
        // _self.$axios.get(_self.https.list.list, params, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
        _self.getList()
      },
      addRow(){
        let _self = this
        _self.boo.showDialog = true
      },
      exportRow(){},
      hiddenRow(){
        
      },
      editRow(){},
      viewRow(item){
        let _self = this
        // let params = {
        //   path: '/product/detail/supply_detail?id=',
        //   query: item.serviceProductNo
        // }
        // _self.$router.push(params.path + params.query)
      },
      addInfo(){
        let _self = this
        _self.currentRow.item7.push({
          'text': ''
        })
      },
      deleteInfo(index){
        let _self = this
        _self.currentRow.item7.splice(index,1)
      },
      submitRow(){

      }
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 62px
  .jx-detail .detail-item .list span
    width: 75px
  .jx-table
    /deep/ .el-table__body td
      .cell
        height: auto
        line-height: auto
  .jx-detail .detail-item .right
    .tel-value 
      width: 220px
</style>
